﻿#ifndef MYCONTROLLER_H
#define MYCONTROLLER_H

#include "crow.h"
#include <string>

class MyController {
public:
    // 注册所有路由
    static void register_routes(crow::SimpleApp& app) {

        // GET / 返回 JSON
        CROW_ROUTE(app, "/")([](){
            crow::json::wvalue res;
            res["code"] = 200;
            res["msg"] = "Hello, Crow MVC JSON!";
            return res;
        });

        // GET /add/<int>/<int> 返回 JSON
        CROW_ROUTE(app, "/add/<int>/<int>")([](int a, int b){
            crow::json::wvalue res;
            res["code"] = 200;
            res["msg"] = "success";
            res["data"]["a"] = a;
            res["data"]["b"] = b;
            res["data"]["sum"] = a + b;
            return res;
        });

        // POST /echo 返回客户端发送的 JSON
        CROW_ROUTE(app, "/echo").methods(crow::HTTPMethod::POST)([](const crow::request& req){
            crow::json::wvalue res;
            res["code"] = 200;
            res["msg"] = "received";
            res["data"]["body"] = req.body;
            return res;
        });
    }
};

#endif
